package com.dji.sample.wayline.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dji.sample.wayline.dao.FlightPlanInfoMapper;
import com.dji.sample.wayline.dao.MemberUserMapper;
import com.dji.sample.wayline.model.entity.FlightPlanInfoEntity;
import com.dji.sample.wayline.model.entity.MemberUserEntity;
import com.dji.sample.wayline.service.FlightPlanInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yjt
 * @date 2023-03-24
 * @description:
 */
@Service
public class FlightPlanInfoServiceImpl implements FlightPlanInfoService {

    @Autowired
    FlightPlanInfoMapper flightPlanInfoMapper;

    @Autowired
    MemberUserMapper memberUserMapper;

    @Override
    public List<FlightPlanInfoEntity> queryList(String mid) {
        MemberUserEntity memberUserEntity = memberUserMapper.selectOne(new LambdaQueryWrapper<MemberUserEntity>().select(MemberUserEntity::getId).eq(MemberUserEntity::getNumber, mid).last(" limit 1 "));
        if (memberUserEntity == null) {
            return new ArrayList<>();
        }
        return flightPlanInfoMapper.selectList(new LambdaQueryWrapper<FlightPlanInfoEntity>().eq(FlightPlanInfoEntity::getPilotIds, memberUserEntity.getId()).or().likeLeft(FlightPlanInfoEntity::getPilotIds, "," + memberUserEntity.getId()).or().like(FlightPlanInfoEntity::getPilotIds,","+memberUserEntity.getId()+",").orderByDesc(FlightPlanInfoEntity::getId));
    }

    @Override
    public FlightPlanInfoEntity queryById(Long id) {
        return flightPlanInfoMapper.selectById(id);
    }

    @Override
    public List<FlightPlanInfoEntity> getByIds(List<Long> ids) {
        return flightPlanInfoMapper.selectBatchIds(ids);
    }
}
